package cuiyt.datastructure.leetcode.queue;


import java.util.Stack;

/**
 * @author cyt
 * @create 2020-12-05 18:27
 */
public class T232 {
    Stack<Integer> outStack;
    Stack<Integer> inStack;

    public T232() {
        this.outStack = new Stack<>();
        this.inStack = new Stack<>();
    }

    /**
     * 使用栈来实现队列的功能
     *
     * @param args
     */
    public static void main(String[] args) {
        T232 t232 = new T232();
        t232.push(2);
        t232.push(3);
        t232.push(4);
        System.out.println(t232.peek());

    }

    public boolean isEmpty() {
        return inStack.isEmpty() && outStack.isEmpty();
    }

    public void push(int x) {
        inStack.push(x);
    }

    public int pop() {
        if (outStack.isEmpty()) {
            while (!inStack.isEmpty()) {
                outStack.push(inStack.pop());
            }
        }
        return outStack.pop();
    }

    public int peek() {
        if (outStack.isEmpty()) {
            while (!inStack.isEmpty()) {
                outStack.push(inStack.pop());
            }
        }
        return outStack.peek();
    }
}
